<template>
  <div class="app-container">
    <el-card class="box-card">
    <el-input v-model="filterText" placeholder="输入需要查找的课程" style="margin-bottom:30px;" />

    <el-tree
      ref="tree2"
      :data="data2"
      :props="defaultProps"
      :filter-node-method="filterNode"
      class="filter-tree"
      default-expand-all
    />
    </el-card>
  </div>
</template>

<script>
import subject from '@/api/edu/subject'


export default {

  data() {
    return {
      filterText: '',
      // 返回所有分类
      data2: [],
      defaultProps: {
        children: 'children',
        label: 'title'
      }
    }
  },
  created() {
    this.getAllSubjectList()
  },
  watch: {
    filterText(val) {
      this.$refs.tree2.filter(val)
    }
  },

  methods: {
    getAllSubjectList() {
      subject.getAllSubject()
        .then(res => {
          this.data2 = res.data.list
        })
    },

    filterNode(value, data) {
      if (!value) return true
      return data.title.toLowerCase().indexOf(value) !== -1
    }
  }
}
</script>

